﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace OA.Repository
{
    /// <summary>
    /// 创建数据上下文的工厂
    /// 目的：保证线程内唯一
    /// </summary>
    public class DbContextFactory
    {
        public static OADbContext CreateContext()
        {
            var context= CallContext.GetData("context") as OADbContext;
            if (context == null)
            {
                context= new OADbContext();
                CallContext.SetData("context", context);
            }
            return context;
        }
    }
}
